package com.huwaiwai.akka.demo02;

import akka.actor.ActorRef;
import akka.actor.Terminated;
import akka.actor.UntypedAbstractActor;
import akka.event.Logging;
import akka.event.LoggingAdapter;

/**
 * Created by huweiwei on 2017/5/16.
 */
public class WatchActor extends UntypedAbstractActor {

    private final LoggingAdapter log = Logging.getLogger(getContext().system(), this);

    public WatchActor(ActorRef ref) {
        getContext().watch(ref);
    }

    @Override
    public void onReceive(Object msg) throws Throwable {
        if (msg instanceof Terminated) {
            System.out.println(((Terminated) msg).getActor().path());
            getContext().system().stop(getSelf());
        }
    }
}
